package cn.shequren.communityPeople.home.model;

import android.content.Context;

import com.jz.community.basecomm.net.retrofit.ApiException;
import com.jz.community.basecomm.net.retrofit.ApiUtils;
import com.jz.community.basecomm.net.retrofit.HttpRxObservable;
import com.jz.community.basecomm.net.retrofit.RxLoadingWrapper;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.basecomm.utils.LoggerUtils;
import com.trello.rxlifecycle2.components.support.RxFragmentActivity;

import cn.shequren.communityPeople.home.bean.ButtomMenuBean;
import cn.shequren.communityPeople.home.bean.VersionBean;
import cn.shequren.communityPeople.home.net.MainApi;
import io.reactivex.Observable;

/**
 * Created by Admin on 2018/3/26 0026.
 */

public class MainModelImpl implements MainModel {

    private Context mContext;

    public MainModelImpl(Context context) {
        mContext = context;
    }

    @Override
    public void updateVersion(String versionName, OnLoadListener<VersionBean> onLoadListener) {
        Observable<VersionBean> observer = HttpRxObservable.getObservable((RxFragmentActivity) mContext, ApiUtils.getApi(mContext, MainApi.class)
                .updateVersion(1,1,versionName));
        new RxLoadingWrapper<VersionBean>(mContext,false)
                .execute(observer)
                .subscribe(resultBean -> {
                    if (resultBean == null) {
                        return;
                    }
                    onLoadListener.onSuccess(resultBean);
                    LoggerUtils.fLog().i("ceshi " + resultBean.toString());
                }, throwable -> onLoadListener.onFail(throwable.toString(), ApiException.handleException(throwable).code));
    }
}
